/*
 * inter_chip.c
 *
 *  Created on: Oct 1, 2013
 *      Author: Ken Arok
 */

#include <string.h>
#include "spi.h"
#include "inter_chip.h"


void vADO_InterChipInit(void)
{
	spi_slave_init();
}


bool vADO_CommandIsReceived(void)
{
	if (spi_command_is_received == true) {
		spi_command_is_received = false;

		return true;
	}

	return false;
}


bool vADO_MessageIsReceived(void)
{
	if (spi_message_is_received == true) {
		spi_message_is_received =  false;

		return true;
	}

	return false;
}

uint8_t vADO_GetCommand(void)
{
	return ado_token[1];
}


void *vADO_GetMessage(void)
{
	return (void *)ado_data;
}


uint8_t vADO_Listen(inter_chip_t *_ic_opt)
{
	uint8_t _ret = 0;
	uint8_t *_ptr;

	if(vADO_CommandIsReceived() == true) {
		_ic_opt->cmd = vADO_GetCommand();
		_ret = 1;
	}
	else if(vADO_MessageIsReceived() ==  true) {
		_ptr = (uint8_t *)vADO_GetMessage();
		_ptr++;
		_ic_opt->pBuf = _ptr;
		_ret = 2;
	}

	return _ret;
}
